package com.example.it.recyclerviewaddheaderandfooter;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

public class HomeActivity extends AppCompatActivity {
    RecyclerView rvList;

    private void initFindViwe() {
        rvList = (RecyclerView) this.findViewById(R.id.rvList);
    }

    private void initAdapter() {
        List<String> stringList = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            stringList.add("news" + (i + 1));
        }

        View headerView = LayoutInflater.from(this).inflate(R.layout.header, null);
        View footerView = LayoutInflater.from(this).inflate(R.layout.footer, null);

        MyRecyclerViewAdapter adapter = new MyRecyclerViewAdapter(this, stringList, R.layout.item);
        adapter.setHeaderView(headerView);
        adapter.setFooterView(footerView);
//        rvList.setLayoutManager(new LinearLayoutManager(this));
//        rvList.setLayoutManager(new GridLayoutManager(this, 3));
        rvList.setLayoutManager(new StaggeredGridLayoutManager(3, 1));
        rvList.setAdapter(adapter);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        initFindViwe();
        initAdapter();
    }
}
